<template>
  <!--  组件的结构-->
  <div class="school">
    <h2>学校名称：{{ name }}</h2>
    <h2>学校地址：{{ address }}</h2>
  </div>
</template>
<script>
//组件交互相关的代码（数据、方法等等）
//   const school=Vue.extend(options)可以简写为 const school=options
import pubsub from 'pubsub-js'

export default {
  name: 'School',
  data() {
    return {
      address: '北京',
      name: '尚硅谷',
    }
  },
  mounted() {
    /*this.pubId = pubsub.subscribe('hello', (msgName, data)=> {
      console.log('有人发布了hello消息，hello消息的回调执行了', msgName, data)
      console.log('this---------',this)
    })*/
    this.pubId = pubsub.subscribe('hello', this.hello)
  },
  beforeDestroy() {
    pubsub.unsubscribe(this.pubId)
  }
  ,
  methods: {
    hello(msgName, data) {
      console.log('有人发布了hello消息，hello消息的回调执行了', msgName, data)
      console.log('this---------', this)
    }
  }
}
</script>
<style scoped>
/*组件的样式*/
.school {
  background-color: gray;
}

</style>